Page({
    data: {
      loading: false
    },
  
    login() {
      this.setData({ loading: true });
      
      // 调用登录接口
      wx.request({
        url: `${getApp().globalData.baseUrl}/api/login`,
        method: 'POST',
        success: (res) => {
          if (res.statusCode === 200) {
            const token = res.data.token;
            // 保存token
            wx.setStorageSync('token', token);
            getApp().globalData.token = token;
            
            // 跳转到首页
            wx.reLaunch({
              url: '/pages/home/home'
            });
          } else {
            wx.showToast({
              title: '登录失败',
              icon: 'none'
            });
          }
        },
        fail: () => {
          wx.showToast({
            title: '网络错误',
            icon: 'none'
          });
        },
        complete: () => {
          this.setData({ loading: false });
        }
      });
    }
  });